package hibernate.web;

import hibernate.fileControler.MyException;
import hibernate.model.Serinoversiyon;
import hibernate.service.EmmyService;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@SuppressWarnings("serial")
@Component("SerinoversiyonBean")
@Scope("session")
public class SerinoversiyonBean implements BeanService {

	@Autowired
	private transient EmmyService emmyService;
	
	private Serinoversiyon selectedSerinover;	
	private List<Serinoversiyon> serinoverList;
	
	@SuppressWarnings("unchecked")
	@Override
	@PostConstruct
	public void init() {
		serinoverList = (List<Serinoversiyon>) emmyService.findAll(new Serinoversiyon());
	}

	@Override
	public String restart() {
		init();
		return "list";
	}

	@Override
	public String deleteView() {
		emmyService.delete(selectedSerinover.getAygitSeriNo());
		init();
		return "list";
	}

	@Override
	public String viewNew() {
		selectedSerinover= new Serinoversiyon();
		return "detail";
	}

	@Override
	public String viewDetail() {/*
		List<Serinoversiyon> valueList = (List<Serinoversiyon>) serinoverTable.getValue();	
		System.out.println("table size : "+valueList.size());		
		Iterator<SimpleRowKey> keys = serinoverTable.getSelection().getKeys();
		
		if(keys.hasNext()){
			currentSerinover= valueList.get(keys.next().intValue());
			System.out.println("dolu = "+currentSerinover.getAygitSeriNo());
			return "detail";
		}else{
			System.out.println("bo�ta");
			return null;
		}*/ return"detay";
	}

	@Override
	public String SaveOrUpdate() throws MyException {
		emmyService.saveOrUpdate(selectedSerinover);
		init();
		return "list";
	}

	@SuppressWarnings("unchecked")
	public String getSerinoVersiyon(long id){		
		serinoverList = (List<Serinoversiyon>) emmyService
					.getQuery("findSrnVerVersiyon", "sVersiyon", id);
		return "list";
	}
	
	@Override
	public String createQuery() {	
		return null;
	}

	@Override
	public void getSession() {
		// TODO Auto-generated method stub
		
	}

	public Serinoversiyon getSelectedSerinover() {
		return selectedSerinover;
	}

	public void setSelectedSerinover(Serinoversiyon selectedSerinover) {
		this.selectedSerinover = selectedSerinover;
	}

	public List<Serinoversiyon> getSerinoverList() {
		return serinoverList;
	}

	public void setSerinoverList(List<Serinoversiyon> serinoverList) {
		this.serinoverList = serinoverList;
	}
}